package liantiaoxifen.server;



import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;

public class Controller {
    private ServerSocket serverSocket;
    public static int count=0;
    private Map<String,PrintWriter> pws=new HashMap<>();


    public Controller(){
        //启动服务器~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        try {
            System.out.println("正在启动服务器~");
            serverSocket=new ServerSocket(8000);
            System.out.println("服务器启动成功！");
        } catch (IOException e) {
            System.out.println("");
            e.printStackTrace();
        }
    }
    public void start(){
        //创建连接 新建线程执行各个用户的会话处理
        try {
            while (true){
                Socket socket=serverSocket.accept();
                count++;
                System.out.println("已经连接上"+count+"个客户端");
                Service m=new Service(socket,pws);
                Thread t=new Thread(m);
                t.start();
            }
        } catch (IOException e) {
            System.out.println("");
            e.printStackTrace();
        }
    }
}
